import dayjs from 'dayjs'
// import { getThemeToken } from './scripts/utils'
// import {
//   VitePluginBlueSkinForVue,
//   VitePluginBlueSkinForScss,
// } from './scripts/blue-skin'

// const themeToken = getThemeToken()

export default defineNuxtConfig({
  devtools: {
    enabled: false
  },
  telemetry: false,
  modules: [
    '@nuxtjs/i18n',
    '@nuxtjs/sitemap',
    '@pinia/nuxt',
    '@pinia-plugin-persistedstate/nuxt',
    '@unocss/nuxt',
    '@vueuse/nuxt',
    'nuxt-svgo'
  ],
  runtimeConfig: {
    public: {
      buildEnv: import.meta.env.NUXT_PUBLIC_BUILD_ENV,
      // 应用构建时间
      appBuildTime: dayjs().format('YYYY-MM-DDTHH:mm:ssZ[Z]'),
      serverOrigin: import.meta.env.NUXT_PUBLIC_SERVER_ORIGIN,
      apiUrlProxyPrefix: import.meta.env.NUXT_PUBLIC_API_URL_PROXY_PREFIX,
      apiUrlBase: import.meta.env.NUXT_PUBLIC_API_URL_BASE,
      imgUrlBase: import.meta.env.NUXT_PUBLIC_IMG_URL_BASE,
      theme: import.meta.env.NUXT_PUBLIC_THEME,
      // AntDesign/UnoCSS 主题配置
      // themeToken,
      tracking: {
        appId: import.meta.env.NUXT_PUBLIC_TRACKING_APP_ID,
        appSecret: import.meta.env.NUXT_PUBLIC_TRACKING_APP_SECRET,
        gt: import.meta.env.NUXT_PUBLIC_TRACKING_ID_GT,
        gtm: import.meta.env.NUXT_PUBLIC_TRACKING_ID_GTM,
        baidu: import.meta.env.NUXT_PUBLIC_TRACKING_ID_BAIDU,
        hubspot: import.meta.env.NUXT_PUBLIC_TRACKING_ID_HUBSPOT
      },
      // cookie 的 key 值配置
      cookie: {
        locale: 'locale',
        token: 'token',
        cookieConsent: 'cookie_consent'
      }
    }
  },
  routeRules: {
    // 首页缓存时间（秒）
    '/zh-cn': {
      swr: import.meta.env.NODE_ENV === 'development' ? false : 60 * 2,
      sitemap: {
        changefreq: 'monthly',
        priority: 1
      }
    },
    '/en': {
      swr: import.meta.env.NODE_ENV === 'development' ? false : 60 * 2,
      sitemap: {
        changefreq: 'monthly',
        priority: 1
      }
    },
    // 收费标准页面缓存
    '/zh-cn/pricing': {
      isr: import.meta.env.NODE_ENV !== 'development',
      sitemap: {
        changefreq: 'monthly',
        priority: 0.8
      }
    },
    '/en/pricing': {
      isr: import.meta.env.NODE_ENV !== 'development',
      sitemap: {
        changefreq: 'monthly',
        priority: 0.8
      }
    },
    // 关于我们页面缓存
    '/zh-cn/about-us': {
      isr: import.meta.env.NODE_ENV !== 'development',
      sitemap: {
        changefreq: 'monthly',
        priority: 0.8
      }
    },
    '/en/about-us': {
      isr: import.meta.env.NODE_ENV !== 'development',
      sitemap: {
        changefreq: 'monthly',
        priority: 0.8
      }
    },
    // Q&A 页面缓存
    '/zh-cn/qna': {
      isr: import.meta.env.NODE_ENV !== 'development',
      sitemap: {
        changefreq: 'monthly',
        priority: 0.7
      }
    },
    '/en/qna': {
      isr: import.meta.env.NODE_ENV !== 'development',
      sitemap: {
        changefreq: 'monthly',
        priority: 0.7
      }
    },
    // 前端 node 服务路由代理（由于线上的 /api 路由已被后端占用）
    '/node/**': {
      proxy: '/api/**'
    },
    // API 请求代理
    [`${import.meta.env.NUXT_PUBLIC_API_URL_PROXY_PREFIX}/**`]: {
      proxy: `${import.meta.env.NUXT_PUBLIC_API_URL_BASE}/**`,
      cors: true
    }
  },
  build: {
    transpile: ['echarts', 'zrender', '@tato30/vue-pdf']
  },
  features: {
    devLogs: false,
    inlineStyles: false
  },
  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          // 注入公共样式
          additionalData: `
            @import "~/styles/theme-token";
            @import "~/styles/variables";
            @import "~/styles/utils";
          `
        },
        less: {
          // modifyVars: {
          //   // arco-design 主题变量
          //   'arcoblue-1': themeToken.unoColorPrimary100,
          //   'arcoblue-2': themeToken.unoColorPrimary200,
          //   'arcoblue-3': themeToken.unoColorPrimary300,
          //   'arcoblue-4': themeToken.unoColorPrimary400,
          //   'arcoblue-5': themeToken.unoColorPrimary500,
          //   'arcoblue-6': themeToken.unoColorPrimary600,
          //   'arcoblue-7': themeToken.unoColorPrimary700,
          //   'arcoblue-8': themeToken.unoColorPrimary800,
          //   'arcoblue-9': themeToken.unoColorPrimary900,
          //   'arcoblue-10': themeToken.unoColorPrimary1000,
          //   'gray-1': themeToken.unoColorGray100,
          //   'gray-2': themeToken.unoColorGray200,
          //   'gray-3': themeToken.unoColorGray300,
          //   'gray-4': themeToken.unoColorGray400,
          //   'gray-5': themeToken.unoColorGray500,
          //   'gray-6': themeToken.unoColorGray600,
          //   'gray-7': themeToken.unoColorGray700,
          //   'gray-8': themeToken.unoColorGray800,
          //   'gray-9': themeToken.unoColorGray900,
          //   'gray-10': themeToken.unoColorGray1000,
          //   'border-radius-small': `${themeToken.borderRadius}px`,
          //   'border-radius-medium': `${themeToken.borderRadius}px`,
          //   'border-radius-large': `${themeToken.borderRadius}px`,
          //   'font-family': themeToken.fontFamily
          // },
          javascriptEnabled: true
        }
      }
    },
    optimizeDeps: {
      esbuildOptions: {
        supported: {
          'top-level-await': true
        }
      }
    },
    esbuild: {
      supported: {
        'top-level-await': true
      }
    }
    // plugins: [VitePluginBlueSkinForVue(), VitePluginBlueSkinForScss()],
  },
  i18n: {
    baseUrl: import.meta.env.NUXT_PUBLIC_SERVER_ORIGIN,
    locales: [
      {
        code: 'zh-cn',
        language: 'zh-CN',
        name: '简体中文',
        isCatchallLocale: true
      },
      {
        code: 'en',
        language: 'en',
        name: 'English',
        isCatchallLocale: true
      }
    ],
    defaultLocale: 'en',
    strategy: 'prefix',
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'locale',
      redirectOn: 'root',
      alwaysRedirect: true,
      fallbackLocale: 'en'
    },
    vueI18n: './locales/config.ts'
  },
  site: {
    url: import.meta.env.NUXT_PUBLIC_SERVER_ORIGIN
  },
  sitemap: {
    exclude: [
      '/home',
      '/redirect',
      /.*\/__dev__\/.+/,
      /.*\/components\/.+/,
      /.*\/composables\/.+/,
      /.*\/utils\/.+/
    ],
    sources: ['/node/__sitemap__/urls'],
    xsl: false,
    cacheMaxAgeSeconds: import.meta.env.NODE_ENV === 'development' ? 0 : 60 * 10,
    debug: import.meta.env.NODE_ENV === 'development'
  },
  svgo: {
    autoImportPath: './assets/icons-blue/',
    componentPrefix: 'icon',
    svgoConfig: {
      multipass: true,
      plugins: [
        {
          name: 'preset-default',
          params: {
            overrides: {
              removeViewBox: false,
              cleanupIds: false,
              cleanupAttrs: false
            }
          }
        }
      ]
    }
  },
  typescript: {
    tsConfig: {
      compilerOptions: {
        allowImportingTsExtensions: true,
        verbatimModuleSyntax: false
      }
    }
  },
  experimental: {
    clientFallback: true,
    componentIslands: true
  },
  compatibilityDate: '2024-08-01'
})
